//
//  ChooseRelatedAddressCell.m
//  HuaRun2
//
//  Created by admin on 2017/11/5.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "ChooseRelatedAddressCell.h"
#import "AddressModel.h"

@interface ChooseRelatedAddressCell ()
//名
@property (nonatomic, strong) UILabel * nameLabel;
//英文
@property (nonatomic, strong) UILabel * englishDesLabel;
//中文
@property (nonatomic, strong) UILabel * chineseDesLabel;
//其他
@property (nonatomic, strong) UILabel * otherDesLabel;

@property (nonatomic, strong) UIButton * iconBtn;

@end

@implementation ChooseRelatedAddressCell

- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        [self viewInit];
        [self layoutInit];
        [self testMethod];
    }
    return self;
}

- (void)testMethod {
//    _nameLabel.text = @"hello";
//    _englishDesLabel.text = [NSString stringWithFormat:@"%@%@",
//                             kTestStr, kTestStr];
//    _chineseDesLabel.text = [NSString stringWithFormat:@"%@%@",
//                             kTestStr, kTestStr];
//    _otherDesLabel.text = [NSString stringWithFormat:@"%@%@",
//                             kTestStr, kTestStr];
    
}

- (void)viewInit {
    
    [super viewInit];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.backView.backgroundColor = RGBA(249, 249, 249, 1);
    
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.englishDesLabel];
    [self.contentView addSubview:self.chineseDesLabel];
    [self.contentView addSubview:self.otherDesLabel];
    [self.contentView addSubview:self.iconBtn];
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(0);
        make.bottom.mas_equalTo(ws.contentView).offset(-kMargin10);
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.backView);
        make.left.mas_equalTo(ws.backView).mas_equalTo(kMargin10);
        make.size.mas_equalTo(CGSizeMake(10, 10));
    }];

    CGFloat width = kMainScreenWidth - 50 - 2 * 10;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.backView).offset(kMargin10/2);
        make.left.mas_equalTo(ws.iconBtn.mas_right).offset(kMargin10);
        make.width.mas_equalTo(width);
    }];
    
    [self.englishDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.nameLabel.mas_bottom).offset(kMargin10);
        make.left.mas_equalTo(ws.nameLabel);
        make.width.mas_equalTo(ws.nameLabel);
    }];

    [self.chineseDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.englishDesLabel.mas_bottom).offset(kMargin10);
        make.left.mas_equalTo(ws.nameLabel);
        make.width.mas_equalTo(ws.nameLabel);
    }];
    [self.otherDesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.chineseDesLabel.mas_bottom).offset(kMargin10);
        make.left.mas_equalTo(ws.nameLabel);
        make.width.mas_equalTo(ws.nameLabel);
        make.bottom.mas_equalTo(ws.contentView).offset(-kMargin10);
    }];

}

#pragma mark setter getter
- (void)setAddressModel:(AddressModel *)addressModel {
    _addressModel = addressModel;
    
    _nameLabel.text = [NSString stringWithFormat:@"%@", addressModel.name? addressModel.name : @""];
    
    _englishDesLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@",
                      addressModel.address1English ? addressModel.address1English : @"",
                      addressModel.address2English ? addressModel.address2English : @"",
                      addressModel.cityTownEnglish ? addressModel.cityTownEnglish : @"",
                      addressModel.stCoProvEnglish ? addressModel.stCoProvEnglish : @""];

    _chineseDesLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@",
                      addressModel.stCoProvChinese ? addressModel.stCoProvChinese : @"",
                      addressModel.cityTownChinese ? addressModel.cityTownChinese : @"",
                      addressModel.address2Chinese ? addressModel.address2Chinese : @"",
                             addressModel.address1Chinese ? addressModel.address1Chinese : @""];
    _otherDesLabel.text =  [NSString stringWithFormat:@"%@ %@ %@",
                            addressModel.zipPostalEnglish ? addressModel.zipPostalEnglish : @"",
                            addressModel.countryEnglish ? addressModel.countryEnglish : @"",
                            addressModel.countryChinese ? addressModel.countryChinese : @""];

  
    if (!addressModel.isSelected) {
        self.backView.backgroundColor = RGBA(249, 249, 249, 1);
    }else {
        self.backView.backgroundColor = [UIColor orangeColor];
    }
    _iconBtn.selected = addressModel.isSelected;
    
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        self.nameLabel = [UILabel new];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.font = [UIFont boldSystemFontOfSize:12];
        _nameLabel.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _nameLabel.text = NSLocalizedString(@"nationality", nil);
//        _nameLabel.backgroundColor = kRandomColor;
    }
    return _nameLabel;
}


- (UILabel *)englishDesLabel {
    if (!_englishDesLabel) {
        self.englishDesLabel = [UILabel new];
        _englishDesLabel.textAlignment = NSTextAlignmentLeft;
        _englishDesLabel.font = kGeneralFontSize;
        _englishDesLabel.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _englishDesLabel.text = @"value";
//        _englishDesLabel.backgroundColor = kRandomColor;
        _englishDesLabel.numberOfLines = 0;
    }
    return _englishDesLabel;
}
- (UILabel *)chineseDesLabel {
    if (!_chineseDesLabel) {
        self.chineseDesLabel = [UILabel new];
        _chineseDesLabel.textAlignment = NSTextAlignmentLeft;
        _chineseDesLabel.font = kGeneralFontSize;
        _chineseDesLabel.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _chineseDesLabel.text = @"value";
//        _chineseDesLabel.backgroundColor = kRandomColor;
        _chineseDesLabel.numberOfLines = 0;
    }
    return _chineseDesLabel;
}


- (UILabel *)otherDesLabel {
    if (!_otherDesLabel) {
        self.otherDesLabel = [UILabel new];
        _otherDesLabel.textAlignment = NSTextAlignmentLeft;
        _otherDesLabel.font = kGeneralFontSize;
        _otherDesLabel.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _otherDesLabel.text = @"value";
//        _otherDesLabel.backgroundColor = kRandomColor;
        _otherDesLabel.numberOfLines = 0;
    }
    return _otherDesLabel;
}

- (UIButton *)iconBtn {
    if (!_iconBtn) {
        self.iconBtn = [UIButton new];
        [_iconBtn setBackgroundImage:[UIImage imageNamed:@"未选中-1"]
                            forState:(UIControlStateNormal)];
        [_iconBtn setBackgroundImage:[UIImage imageNamed:@"选中按钮"]
                            forState:(UIControlStateSelected)];
        _iconBtn.userInteractionEnabled = NO;
    }
    return _iconBtn;
}
@end
